import { NextFunction, Request, Response } from 'express'
import { mongodbDataSource, mysqlDataSource } from '@/utils/database'
import DBServerError from '@/errors/DBServerError'

// 中间件检查数据库连接状态
export default (_req: Request, _res: Response, next: NextFunction) => {
  if (!mysqlDataSource.isInitialized || !mongodbDataSource.isInitialized) {
    throw new DBServerError('数据服务异常')
  }
  next()
}
